package down.sallai.ml.config;

import down.sallai.ml.interceptor.GithubInterceptor;
import down.sallai.ml.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Bean
    public GithubInterceptor getGithubInterceptorInstance(){
        return new GithubInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/admin/**")
                .excludePathPatterns("/login");
        registry.addInterceptor(getGithubInterceptorInstance())
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**")
//                .excludePathPatterns("/img")
//                .excludePathPatterns("/","/index.html","/index")
                .excludePathPatterns("/wxapi/**");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

}